package com.itheima.health.job;

import com.itheima.health.constant.RedisConstant;
import com.itheima.health.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Date;
import java.util.Iterator;
import java.util.Set;

public class ClearImgJob {
    @Autowired
    JedisPool jedisPool;

     public void clearImg(){
         Set<String> set = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES,
                 RedisConstant.SETMEAL_PIC_DB_RESOURCES);
         Iterator<String> iterator = set.iterator();
         while (iterator.hasNext()){
             String pic = iterator.next();
             QiniuUtils.deleteFileFromQiniu(pic);
             jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,pic);
             System.out.println(new Date());

         }

     }
}
